package com.zwg.tingshu.dispatch.job;

import com.zwg.tingshu.search.client.SearchFeignClient;
import com.zwg.tingshu.user.client.UserFeignClient;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DispatchHandler {
    @Autowired
    private SearchFeignClient searchFeignClient;
    @Autowired
    private UserFeignClient userFeignClient;


    /**
     * 定时执行更新会员状态
     * @return
     */
    @XxlJob("updateUserVIPStatusJob")
    public ReturnT updateUserVIPStatusJob() {
        try {
            String jobParam = XxlJobHelper.getJobParam();
            log.info("定时执行会员状态:{}", jobParam);
            userFeignClient.updateVipExpireStatus();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            return ReturnT.FAIL;
        }
    }

    @XxlJob("shardJob")
    public void shardJob(){
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        log.info("总分片数：{}", shardTotal);
        log.info("分片索引：{}", shardIndex);
    }

    /**
     * 定时执行热门专辑更新
     */
    @XxlJob("updateHotAlbumJob")
    public void updateHotAlbumJob() {
        log.info("定时执行热门专辑更新");
        searchFeignClient.updateLatelyAlbumRanking();
    }

}